<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" id="viewport"
	content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no" />
<link rel="stylesheet" href="./css/ydui.css" type="text/css" />
<link rel="stylesheet" href="./css/demo.css" type="text/css" />
<link href="./css/reset.css" rel="stylesheet" type="text/css">
<link href="./css/receiving-adress.css" rel="stylesheet" type="text/css">
<script src="./js/ydui.flexible.js"></script>
</head>
<body>
	<div class="near-box">
		<div class="header">
			<a href="javascript:history.back(-1)" class="left"></a>
			收货地址
		</div>
		<div class="bigbox">
			<div class="receiv-text1">地址信息</div>
			<div class="receiv-box1">
				<input type="text" id="name" class="receiv-input1" placeholder="收货人姓名（请使用真实姓名）">
			</div>
			<div class="receiv-box1">
				<input type="number" id="mobile" class="receiv-input1" placeholder="手机号码">
			</div>
			<div class="delivery-layer-box">
				<div class="cell-item">
					<div class="cell-right cell-arrow">
						<input type="text" class="cell-input" readonly id="J_Address" placeholder="请选择收货地址">
					</div>
				</div>
			</div>
			<div class="receiv-box2">
				<textarea class="receiv-input2" placeholder="详细地址,示例：上海电机学院35号楼" id="district"></textarea>
			</div>
			<button class="set-text1" id="validateBtn">保存</button>
		</div>

	</div>
	<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
	<script type="text/javascript" src="./js/ydui.citys.js"></script>
	<script type="text/javascript" src="./js/ydui.js"></script>
	<script type="text/javascript">
	/**
 * 默认调用
 */
!function () {
	var $target = $('#J_Address');

	$target.citySelect();

	$target.on('click', function (event) {
		event.stopPropagation();
		$target.citySelect('open');
	});

	$target.on('done.ydui.cityselect', function (ret) {
		$(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
	});
}();


$(function() {
		
	$('#validateBtn').click(function() {
			var name = $('#name').val();
			var mobile = $('#mobile').val();
			var adress = $('#J_Address').val();
			var district= $('#district').val();
			if (name == '') {
				alert('收货人不能为空');
				return;
			}
			if (mobile == '') {
				alert('手机号不能为空');
				return;
			}
			if (adress == '') {
				alert('地址不能为空');
				return;
			}
			if (district == '') {
				alert('请填写详细地址');
				return;
			}
			adress = adress + district; //拼接详细地址
			
			if(adress.indexOf("海洋") != -1){
				district="上海海洋大学";
			}else if(adress.indexOf("海事") != -1){
				district="上海海事大学";
			}else if(adress.indexOf("电机") != -1){
				district="上海电机学院";
			}else if(adress.indexOf("建桥") != -1){
				district="上海建桥学院";
			}else if(adress.indexOf("电力") != -1){
				district="上海电力大学";
			}else{
				district="社区";
			}
			
			 
			$.ajax({
				type : 'POST',
				url : '/carworld_weixin/user/supplyUserInfo',
				data : {
					'name' : name,
					'mobile' : mobile,
					'adress' : adress,
					'district' : district
				},
				dataType : 'text',
				success : function(result) {
					if(result=='success'){
						window.location.href='/carworld_weixin/ssx/indent-details.html';
					}else{
						alert('地址信息补充失败，请联系客服~');
						window.location.href='/carworld_weixin/';
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(textStatus);
					
				}
			}); 

		})
	
})



</script>
</body>
</html>